---
title: Dependencies
sidebar_label: "Basics"
---

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
import PartialDependenciesConfig from '../_partials/v2beta1/dependencies.mdx'

DevSpace allows you to define dependencies between several software projects that have a `devspace.yaml`, e.g. across different git repositories or local folders. This makes DevSpace a great tool for building and deploying software that consists of several microservices. Primary use cases of dependencies are:

- You want to reuse an already existing `devspace.yaml` of another project
- You want to define a more complex pipeline with multiple build, hook and deploy steps
- You want to define a common build / deploy step for other projects

Dependencies for DevSpace projects are defined within the `dependencies` section of `devspace.yaml`.

<Tabs
  defaultValue="git"
  values={[
    { label: 'Git Repository', value: 'git', },
    { label: 'Local Path', value: 'path', },
  ]
}>
<TabItem value="git">

```yaml
dependencies:
  api-server:
    git: https://github.com/my-api-server
    branch: stable
    pipeline: dev
  auth-server:
    git: https://github.com/my-auth-server
    revision: c967392
    profiles:
      - production
  database-server:
    git: https://github.com/my-database-server
    tag: v3.0.1
    subPath: /configuration
    vars:
      ROOT_PASSWORD: ${ROOT_PASSWORD}
```

</TabItem>
<TabItem value="path">

```yaml
dependencies:
  component-1:
    path: ./component-1
  component-2:
    path: ./component-2
```

</TabItem>
</Tabs>

## Dependency Source
DevSpace is able to work with dependencies from the following sources:
- [`git` repository](../../configuration/dependencies/git-repository.mdx) as dependency that has a devspace configuration
- [`path` to a local folder](../../configuration/dependencies/local-folder.mdx) that contains a dependency (path is relative to the current project's root directory)


## Execution Order

Dependencies will be executed in parallel and always before image building and deployments defined in the top-level `devspace.yaml`. If you want to execute dependencies sequentially, you can define a pipeline to do so. `dev` configuration that should be reused from a dependency will be executed alongside regular `dev` configuration specified in the top-level `devspace.yaml` after the DevSpace deployment pipeline ran through. Example:
```yaml
dependencies:
  dep1:
    path: dep1
    pipeline: dev
  dep2:
    path: dep2
    pipeline: dev
images:
  image1:
    image: myimage/image
deployments:
  deployment1:
    helm:
      ...
dev:
  my-dev:
    ports: ...
    sync: ...
```

### Explanation
In the above `devspace.yaml`, execution order would be as followed:
* Execute dependency dep1's pull secrets, image building & deployments (if dep1 has other dependencies as well, execute those first)
* Execute dependency dep2's pull secrets, image building & deployments
* Build image `image1`
* Deploy deployment `deployment1`
* Start merged portforwarding from `dep2` and `dev.ports`
* Start sync from `dep1` and `dev.sync`

## Referencing Dependencies

### Reference Image Names
You can reference dependencies images via `my-dependency.image` in the `./devspace.yaml`:
```yaml
dependencies:
  dep1:
    path: dep1

dev:
  my-dev:
    imageSelector: ${runtime.dependencies.dep1.images.image1}
    # Will open a terminal to the pod with the
    # image from dep1
    terminal: {}
```

With `dep1/devspace.yaml`:
```yaml
images:
  image1:
    image: myusername/devspace
deployments:
  quickstart:
    helm:
      values:
        containers:
          - image: myusername/devspace
```

### Referencing Dependencies in Deployment Values / Manifests

It is also possible to reference a dependency's image with runtime variables in a deployment:
```yaml
dependencies:
  dep1:
    path: dep1
deployments:
  quickstart:
    helm:
      values:
        containers:
          - image: ${runtime.dependencies.dep1.image1.image}:${runtime.dependencies.dep1.image1.tag} # -> replaced with 'myusername/devspace:xxxx'
```

With a dependency `dep1/devspace.yaml` that looks like:
```yaml
images:
  image1:
    image: myusername/devspace
```

## Dependency Resolution
When a DevSpace project has dependencies, DevSpace will:

1. Resolve all dependencies in a recursive manner and give the dependency an ID based on its path or git repository
2. Build a non-cyclic dependency tree where each dependency only occurs once (but could have multiple edges)
3. Choose a leave node from the dependency tree, build its images (unless skip is defined) and deploy its deployments as well as execute defined hooks or pull secrets
4. Remove the leave node from the tree and repeat step 3 until everything has been deployed

The algorithm used by DevSpace for building and deploying dependencies ensures that all dependencies have been deployed in the correct order before the project you are calling DevSpace from will be built and deployed.

### Redundant Dependencies
If DevSpace detects that two projects within the dependency tree define the same child-dependency (i.e. a redundant dependency), DevSpace will try to resolve this by removing the dependency that is "higher" (i.e. found first when resolving dependencies) within the tree.

### Circular Dependencies
If DevSpace detects two projects which define each other as dependencies (either directly or via child-dependencies), DevSpace will print a warning showing the problematic dependency path within the dependency tree.

## Configuration

<PartialDependenciesConfig/>
